const workerList = [];

self.addEventListener('connect', event => {
    const port = event.ports[0];
    workerList.push(port); // 存储已连接的port

    port.onmessage = event => {
        workerList.forEach(p => { // 遍历所有已连接的port，发送消息
            p.postMessage("接收到消息: " + event.data);
        })
    };

    port.start()// 开启端口
});